package cn.lintcode;

/**
 * @author labvi
 * @version 1.0.0
 */
public class RemoveDupFromArray {
    public  static  int removeDuplicates(int[] nums) {
        // write your code here
        if (null == nums || nums.length < 1){
            return 0;
        }

        int size = 0;
        int count = 1;
        for (int i = 1; i< nums.length ;i++ ){
            //前一个数和后一个数相等
            if (nums[size] == nums[i]) {
                if (count < 2) {
                    nums[++size] = nums[i];
                    count++;
                }
                //前一个数和后一个数不相等
                //size向后移动 ,count恢复计数
            } else {
                nums[++size] = nums[i];
                count = 1;
            }
        }
        return size+1;
    }

    public static void main(String[] args) {
        int[] arr = {1,1,1,2,2};
        removeDuplicates(arr);
    }
}
